package com.shanghai.market.plshnaghai.publics;

import android.content.Context;
import android.view.LayoutInflater;
import android.widget.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

public abstract class BasePTAdapter<T> extends BaseAdapter {
    protected List<T> mDatas;
    protected Context mContext;
    protected LayoutInflater mInflater;

    public BasePTAdapter(Context context) {
        super();
        mContext = context;
        mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mDatas = new ArrayList<T>();
    }

    public List<T> getListData() {
        return mDatas;
    }

    public void addItem(T data) {
        mDatas.add(data);
    }

    public void addItems(List<? extends T> datas) {
        if (datas != null && !datas.isEmpty()) {
            mDatas.addAll(datas);
        }
    }

    public void removeItem(T data) {
        if (mDatas.contains(data)) {
            mDatas.remove(data);
        }
    }

    public void removeAll() {
        mDatas.clear();
    }

    public int getItemPosition(T data) {
        return mDatas.indexOf(data);
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public T getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

}
